#define _CRT_SECURE_NO_WARNINGS 1
#include <vector>
using namespace std;
class Solution {
public:
    int maxSubArray(vector<int>& nums)
    {
        int n = nums.size();
        int ret = INT_MIN;
        vector<int> dp(n + 1, 0);
        for (int i = 1; i <= n; i++)
        {
            dp[i] = max(nums[i - 1], dp[i - 1] + nums[i - 1]);
            ret = max(ret, dp[i]);
        }
        return ret;
    }
};

class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums)
    {
        // int n = nums.size();
        // vector<int> arr1(n,1),arr2(n,1),ret(n);

        // for(int i = 1; i < n; i++)
        //     arr1[i] = arr1[i-1] * nums[i-1];
        // for(int i = n-2; i >= 0; i--)
        //     arr2[i] = arr2[i+1] * nums[i+1];
        // for(int i = 0; i < n; i++)
        // {
        //     ret[i] = arr1[i] * arr2[i]; 
        // }
        // return ret;

        int n = nums.size();
        vector<int> ret(n, 1);
        int right = 1;
        for (int i = 1; i < n; i++)
            ret[i] = ret[i - 1] * nums[i - 1];
        for (int i = n - 2; i >= 0; i--)
        {
            right *= nums[i + 1];
            ret[i] *= right;
        }
        return ret;
    }
};